package com.dime.physical.controller;

import com.dime.basic.api.RemoteOccupationalBasicService;
import com.dime.basic.api.model.OccupationalBasic;
import com.dime.mninterface.api.RemoteHealth100Service;
import com.dime.mninterface.api.model.*;
import com.dime.physical.model.OccupationalEmployeeAnalysisVO;
import com.dime.physical.model.OccupationalCheckMainVO;
import com.dime.physical.model.OccupationalMainVO;
import com.dime.physical.model.dto.OccupationHealthCheckEmployeesDto;
import com.dime.physical.service.IDimePhysicalOccupationalService;
import com.ruoyi.common.core.constant.SecurityConstants;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.common.security.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/dimeTest")
public class DimeTestController {
    @Autowired
    private RemoteHealth100Service remoteHealth_100Service;
    @Autowired
    private RemoteOccupationalBasicService remoteOccupationalBasicService;

    @Autowired
    private IDimePhysicalOccupationalService occupationalService;
    @RequiresPermissions("tool:gen:list")
    @GetMapping("/list")
    public List<MNOrderDetail> genList()
    {
        String shopCode = SecurityUtils.getShopId();
        OrderRequestBody requestBody = new OrderRequestBody();
        requestBody.setBranchCode(shopCode);
        requestBody.setClientSource(0L);
        requestBody.setVerifyScope(0L);
        requestBody.setOrderCode("SOA36892923234110249");
        try {
            MNResponse<List<MNOrderDetail>> t = remoteHealth_100Service.getOrder(requestBody);
            if(t.getCode() != "500") {
                return t.getData();
            }
        }catch (Exception ex) {

        }
        return null;
    }

    @RequiresPermissions("tool:gen:list")
    @GetMapping("/report")
    public MNReport genReport()
    {
        String shopCode = SecurityUtils.getShopId();
        ReportRequestBody requestBody = new ReportRequestBody();
        requestBody.setBranchCode(shopCode);

        requestBody.setServiceUid("1701378331961810947");
        try {
            MNResponse<MNReport> t = remoteHealth_100Service.getReport(requestBody);
            if(t.getCode() != "500") {
                return t.getData();
            }
        }catch (Exception ex) {

        }
        return null;
    }

    @RequiresPermissions("tool:gen:list")
    @GetMapping("/regist")
    public MNResponseBase genregist()
    {
        String shopCode = SecurityUtils.getShopId();
        RegistRequestBody requestBody = new RegistRequestBody();
        requestBody.setBranchCode("8W");

        requestBody.setCertificateNumber("412721198210181036");
        try {
            MNResponse<List<MNRegist>> t = remoteHealth_100Service.getRegist(requestBody);
            if(t.getCode() != "500") {
                return t;
            }
        }catch (Exception ex) {

        }
        return null;
    }

    @RequiresPermissions("tool:gen:list")
    @GetMapping("/getoccupationalbasic")
    public R<OccupationalBasic> getoccupationalbasic()
    {
        try {
            R<OccupationalBasic> t = remoteOccupationalBasicService.occupationalBasic(SecurityConstants.INNER);
            if(t.getCode() != 500) {
                return t;
            }
        }catch (Exception ex) {

        }
        return null;
    }
    @RequiresPermissions("tool:gen:list")
    @GetMapping("/getOccupationalEmployeeAnalysis")
    public R<List<OccupationalEmployeeAnalysisVO>> getOccupationalEmployeeAnalysis()
    {
        Date start = DateUtils.parseDate("2023-08-01");
        Date end = DateUtils.parseDate("2023-12-01");
/*        OccupationHealthCheckEmployeesDto dto = OccupationHealthCheckEmployeesDto.builder()
                .checkDateEnd(end)
                .checkDateStart(start)
                .selectAll(true)
                .build();*/
        try {
            List<OccupationalEmployeeAnalysisVO> t = occupationalService.testgetemployeeAnalysis(new OccupationHealthCheckEmployeesDto());
            return R.ok(t);
        }catch (Exception ex) {
            return null;
        }

    }

    @RequiresPermissions("tool:gen:list")
    @GetMapping("/getOccupationalEmployeeList")
    public R<List<OccupationalCheckMainVO>> getOccupationalEmployees()
    {
        Date start = DateUtils.parseDate("2023-08-01");
        Date end = DateUtils.parseDate("2023-12-01");
      /*  OccupationHealthCheckEmployeesDto dto = OccupationHealthCheckEmployeesDto.builder()
                .checkDateEnd(end)
                .checkDateStart(start)
                .selectAll(true)
                .build();*/
        try {
            List<OccupationalCheckMainVO> t = occupationalService.testgetemployees(new OccupationHealthCheckEmployeesDto());
            return R.ok(t);
        }catch (Exception ex) {
            return null;
        }

    }

    @RequiresPermissions("tool:gen:list")
    @GetMapping("/getOccupationalHealthCheck")
    public R<OccupationalMainVO> OccupationalHealthCheck()
    {
        List<String> employees = new ArrayList<>();
        employees.add("094eea0a-0aee-44ee-9781-3c033f726fe0");
        employees.add("41c2cf55-8aed-4ff3-a965-6fc56472a785");
        Date start = DateUtils.parseDate("2023-08-01");
        Date end = DateUtils.parseDate("2023-12-01");
        OccupationHealthCheckEmployeesDto dto = OccupationHealthCheckEmployeesDto.builder()
                .checkDateEnd(end)
                .checkDateStart(start)
                .companyId("3e921af3-f46d-4347-b832-16dd891504f3")
                .employees(employees)
                .selectAll(false)
                .build();
        try {
            OccupationalMainVO t = occupationalService.occupationalHealthCheck(dto);
            return R.ok(t);
        }catch (Exception ex) {
            throw ex;
        }

    }
}
